﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Workbench.Models;
using Workbench.Persistance;

namespace Workbench.Operations
{
    public static class ConcordanceOperations
    {
        public static List<WordWithNearWordsModel> GetNearWords(WordSuggestionModel wordModel, SuggestionType suggestionType)
        {
            var rootDirectory = ProjectOperations.GetRootDirectory();
            var repo = DBContext.Current.GetConcordancerRepository();
            var words = repo.GetNearWords(rootDirectory.GetContextIncludedFiles(), wordModel, suggestionType);
            return words;
        }

        public static List<WordSuggestionModel> GetSuggestions(string currentSearchContent, SuggestionType suggestionType)
        {
            var result = new List<WordSuggestionModel>();
            if (currentSearchContent != null)
            {
                var rootDirectory = ProjectOperations.GetRootDirectory();
                var repo = DBContext.Current.GetConcordancerRepository();
                result = repo.GetWordFormSuggestions(rootDirectory.GetContextIncludedFiles(), currentSearchContent, suggestionType);
            }
            return result;
        }

        public static Task<List<WordSuggestionModel>> GetSuggestionsAsync(string currentSearchContent, SuggestionType suggestionType)
        {
            return Task<List<WordSuggestionModel>>.Run(() =>
            { 
                var result = new List<WordSuggestionModel>();
                if (currentSearchContent != null)
                {
                    var rootDirectory = ProjectOperations.GetRootDirectory();
                    var repo = DBContext.Current.GetConcordancerRepository();
                    result = repo.GetWordFormSuggestions(rootDirectory.GetContextIncludedFiles(), currentSearchContent, suggestionType); 
                }
                return result;
            });
        }
    }
}
